package GameMain.Model
{
	import GameMain.Macro.MacroSound;
	
	import flash.display.LoaderInfo;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	public class SoundManager
	{
		
		private var _soundGameErea:Sound = null;
		private var _soundPon:Sound = null;
		private var _soundPata:Sound = null;
		private var _soundDon:Sound = null;
		private var _soundChaka:Sound = null;
		private var _soundPonEcho:Sound = null;
		private var _soundPataEcho:Sound = null;
		private var _soundDonEcho:Sound = null;
		private var _soundChakaEcho:Sound = null;
		private var _channelGameErea:SoundChannel = null;
		
		public function SoundManager()
		{
			
		}
		
		public function initSoundMgr(info:LoaderInfo):void
		{
			var _class:Class = info.applicationDomain.getDefinition("GameSound.GameAreaMusic") as Class;
			this._soundGameErea = new _class as Sound;
			_class = info.applicationDomain.getDefinition("GameSound.Pon") as Class;
			this._soundPon = new _class as Sound;
			_class = info.applicationDomain.getDefinition("GameSound.Pata") as Class;
			this._soundPata = new _class as Sound;
			_class = info.applicationDomain.getDefinition("GameSound.Don") as Class;
			this._soundDon = new _class as Sound;
			_class = info.applicationDomain.getDefinition("GameSound.Chaka") as Class;
			this._soundChaka = new _class as Sound;
			
			_class = info.applicationDomain.getDefinition("GameSound.Ponecho") as Class;
			this._soundPonEcho = new _class as Sound;
			
			_class = info.applicationDomain.getDefinition("GameSound.Pataecho") as Class;
			this._soundPataEcho = new _class as Sound;
			
			_class = info.applicationDomain.getDefinition("GameSound.Donecho") as Class;
			this._soundDonEcho = new _class as Sound;
			
			_class = info.applicationDomain.getDefinition("GameSound.Chakaecho") as Class;
			this._soundChakaEcho = new _class as Sound;
			
			
		}
		
		public function soundPlay(soundtype:int):void
		{
			switch(soundtype)
			{
				case MacroSound.SOUND_GAME_EREA:
					this.playGameEreaMusic();
					break;
				case MacroSound.SOUND_PON:
					this._soundPon.play(0);
					break;
				case MacroSound.SOUND_CHAKA:
					this._soundChaka.play(0,1);
					break;
				case MacroSound.SOUND_DON:
					this._soundDon.play(0,1);
					break;
				case MacroSound.SOUND_PATA:
					this._soundPata.play(0);
					break;
				case MacroSound.SOUND_PON_ECHO:
					this._soundPonEcho.play(0);
					break;
				case MacroSound.SOUND_CHAKA_ECHO:
					this._soundChakaEcho.play(0);
					break;
				case MacroSound.SOUND_DON_ECHO:
					this._soundDonEcho.play(0);
					break;
				case MacroSound.SOUND_PATA_ECHO:
					this._soundPataEcho.play(0);
					break;
				default:
					break;
			}
		}
		
		public function soundClose(soundtype:int):void
		{
			switch(soundtype)
			{
				case MacroSound.SOUND_GAME_EREA:
					this.closeGameEreaMusic();
					break;
				default:
					break;
			}
		}
		
		private function playGameEreaMusic():void
		{
			if(this._channelGameErea == null)
			{
				this._channelGameErea = this._soundGameErea.play();
				this._channelGameErea.soundTransform = new SoundTransform(0.5);
			}
		}
		
		private function closeGameEreaMusic():void
		{
			if(this._channelGameErea != null)
			{
				this._channelGameErea.stop();
				this._channelGameErea = null;
			}
		}
	}
}